﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xxx.Candidates.System.Interfaces.IService;
using xxx.Candidates.System.Model.View;

namespace xxx.Candidates.System.Interfaces.Service
{
    public class ZigZagReorderStrategy : IReorderStrategy
    {
        public IEnumerable<CandidateListVM> Reorder(IEnumerable<CandidateListVM> candidates)
        {
            var list = candidates.ToList();
            var result = new List<CandidateListVM>();
            int left = 0, right = list.Count - 1;

            while (left <= right)
            {
                result.Add(list[left]);
                if (left != right) result.Add(list[right]);
                left++;
                right--;
            }
            return result;
        }
    }
}
